#include "StdAfx.h"
#include "ClienteleManager.h"
#include "Utils.h"


ClienteleManager* ClienteleManager::m_instance = nullptr;

ClienteleManager* ClienteleManager::getInstance()
{
	if (nullptr == m_instance)
	{
		m_instance = new ClienteleManager();
	}

	return m_instance;
}

ClienteleManager::ClienteleManager(void)
{
	m_pvtClienteleInfos = new vector<ClienteleInfo*>();
	m_pvtCliWillInfo = new vector<ClienteleInfo*>();
	m_dataType = Auto_Dispath;
}


ClienteleManager::~ClienteleManager(void)
{	
	vector<ClienteleInfo*>::iterator vtIt = m_pvtClienteleInfos->begin();
	for (; vtIt != m_pvtClienteleInfos->end(); ++vtIt)
	{
		SAFE_RELEASE(*vtIt);
	}
	SAFE_RELEASE(m_pvtClienteleInfos);

	vtIt = m_pvtCliWillInfo->begin();
	for (; vtIt != m_pvtCliWillInfo->end(); ++vtIt)
	{
		SAFE_RELEASE(*vtIt);
	}
	SAFE_RELEASE(m_pvtCliWillInfo);

	vtIt = m_vtSearchClientRes.begin();
	for (; vtIt != m_vtSearchClientRes.end(); ++vtIt)
	{
		SAFE_RELEASE(*vtIt);
	}
	m_vtSearchClientRes.clear();

	clearConditionSearchResult();
}

void ClienteleManager::clearSearchResult()
{
	vector<ClienteleInfo*>::iterator vtIt = m_vtSearchClientRes.begin();
	for (; vtIt != m_vtSearchClientRes.end(); ++vtIt)
	{
		SAFE_RELEASE(*vtIt);
	}
	m_vtSearchClientRes.clear();
}

void ClienteleManager::clearConditionSearchResult()
{
	vector<ClienteleInfo*>::iterator vtIt = m_vtConditionSearchResult.begin();
	for (; vtIt != m_vtConditionSearchResult.end(); ++vtIt)
	{
		SAFE_RELEASE(*vtIt);
	}
	m_vtConditionSearchResult.clear();
}

void ClienteleManager::clear()
{
	if (Auto_Dispath == m_dataType)
	{
		vector<ClienteleInfo*>::iterator vtIt = m_pvtClienteleInfos->begin();
		for (; vtIt != m_pvtClienteleInfos->end(); ++vtIt)
		{
			SAFE_RELEASE(*vtIt);
		}
		m_pvtClienteleInfos->clear();
	}
	else if (Dev_Client == m_dataType)
	{
		vector<ClienteleInfo*>::iterator vtIt = m_pvtCliWillInfo->begin();
		for (; vtIt != m_pvtCliWillInfo->end(); ++vtIt)
		{
			SAFE_RELEASE(*vtIt);
		}
		m_pvtCliWillInfo->clear();
	}	
}

vector<ClienteleInfo*>* ClienteleManager::getCurrentUsingClientls()
{
	if (Auto_Dispath == m_dataType)
	{
		return m_pvtClienteleInfos;
	}
	else if (Dev_Client == m_dataType)
	{
		return m_pvtCliWillInfo;
	}
	else if (Condition_Search == m_dataType)
	{
		return &m_vtConditionSearchResult;
	}
}
